using System;
using System.Reflection;

namespace Meta
{
	/// <summary>
	/// Summary description for EventWrapper.
	/// </summary>
	public class Event : ApplyInterfaceProcedure
	{
		public object targetObject;
		public EventInfo targetEvent;

		public Event(object o, EventInfo e)
		{
			this.targetObject = o;
			this.targetEvent = e;
			this.name = e.Name;
		}

		public void Add(object handler) {
			targetEvent.AddEventHandler(targetObject, DelegateGenerator.AsDelegate(targetEvent.EventHandlerType, handler));
		}

		public void Remove(System.Delegate handler) {
			targetEvent.RemoveEventHandler(targetObject, handler);
		}

		public override object Apply(object[] args) {
			return targetEvent.GetRaiseMethod().Invoke(targetObject, args);
		}
	}
}
